<br>
<i id="wallet_min_warning" class="walminwarn" style="float:right" title="Modify MinValue in gocoin.conf to change it">
Minimum output value to be included in wallet's balance: <b id="min_val_btc"></b> BTC</i>
<div id="wal_off" style="display:none">
Wallet functionality is not available at this moment.

<div id="wal_oin" style="display:none"><br>It will auto enable in <b id="ais"></b>...</div>

<form id="form_a" method="post" action="cfg" style="margin-top:20px;display:none">
<input type="hidden" name="wallet" value="on">
<input type="hidden" name="page" id="page_a">
<input type="submit" id="enable_wallet_button" value="Enable wallet functionality now">
</form>
</div>

<div id="wal_pro" style="display:none">
Wallet functionality is being enabled - <b id="perc_compl"></b> complete

<form id="form_b" method="post" action="cfg" style="margin-top:20px;display:none">
<input type="hidden" name="wallet" value="off">
<input type="hidden" name="page" id="page_b">
<input type="submit" value="Abort enabling wallet functionality">
</form>
</div>
</div>

<script>

function hande_stat(stat) {
	if (stat.WalletON) {
		location.reload()
		return 0
	}

	if (stat.WalletProgress==0) {
		wal_off.style.display = 'block'
		wal_pro.style.display = 'none'

		if (stat.WalletOnIn == 0) {
			// disabled and not pending
			wal_oin.style.display = 'none'
			return 3000
		}

		ais.innerText = stat.WalletOnIn
		wal_oin.style.display = 'block'
		return 1000
	}

	// in progress
	perc_compl.innerText = (stat.WalletProgress/10).toFixed(0) + '%'
	wal_off.style.display = 'none'
	wal_pro.style.display = 'block'
	return 1000
}

function refresh_walletstatus() {
	var aj = ajax()
	aj.onerror=function() {
		setTimeout(refresh_walletstatus, 5000)
	}
	aj.onload=function() {
		var to = 5000
		try {
			to = hande_stat(JSON.parse(aj.responseText))
		} catch(e) {
			console.log(e)
		}
		if (to > 0)  setTimeout(refresh_walletstatus, to)
	}
	aj.open("GET","walsta.json",true)
	aj.send(null)
}

if (!server_mode) {
	page_a.value = document.location
	page_b.value = document.location
	form_a.style.display = 'block'
	form_b.style.display = 'block'
}
refresh_walletstatus()

var _lblo = 0
blno.addEventListener("lastblock", function(e) {
	if (_lblo==0) {
		_lblo = e.block.Height
		min_val_btc.innerText = val2str(e.block.MinValue)
	}
})

if (!chain_in_sync) {
	enable_wallet_button.disabled = true
	enable_wallet_button.title = 'Cannot enable when block chain sync in progress'
}

</script>
